home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / cbm / 1194 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: merle.acns.nwu.edu!judd
  2. From: judd@merle.acns.nwu.edu (Stephen Judd)
  3. Newsgroups: comp.sys.cbm
  4. Subject: Re: PROGRAMMING- MUL's DIV's
  5. Date: 24 Jan 1996 17:27:21 GMT
  6. Organization: Northwestern University, Evanston IL
  7. Message-ID: <4e5q5p$ekt@news.acns.nwu.edu>
  8. References: <4e5dp2$m4i@sun1000.pwr.wroc.pl>
  9. Reply-To: sjudd@nwu.edu (Stephen Judd)
  10. NNTP-Posting-Host: merle.acns.nwu.edu
  11.  
  12. In article <4e5dp2$m4i@sun1000.pwr.wroc.pl>,
  13. A Member of Elysium <st103@sco.zsi.pwr.wroc.pl> wrote:
  14. >Hi!
  15. >
  16. >I'm going to write some math stuff for my c64 byt i have a little problem:
  17. >i need a 16 bits * 16 bits multiplication program and 16 bits / 8 bits or 8 bits / 8 bits division program that will return not the integer and fractional part of the number. I dont expect ANY optimized solutions i just wan a basic version that is slow but works. Can any one help me? Aspecialy with the division ?
  18. >
  19. >Kris
  20. >
  21.  
  22. Straightforward 16-bit routines, coming right up:
  23.  
  24. *------------------------
  25.  
  26. * 16-bit Multiply routine
  27.  
  28. * ACC*AUX -> [ACC,EXT] (low,hi) 32-bit result
  29.  
  30. MULT    LDA #0
  31.     STA EXT+1
  32.     LDY #$11
  33. ]LOOP    LSR EXT+1
  34.     ROR
  35.     ROR ACC+1
  36.     ROR ACC
  37.     BCC MUL2
  38.     CLC
  39.     ADC AUX
  40.     PHA
  41.     LDA AUX+1
  42.     ADC EXT+1
  43.     STA EXT+1
  44.     PLA
  45. MUL2    DEY
  46.     BNE ]LOOP
  47.     STA EXT
  48.     RTS
  49.  
  50. * Divide routine
  51.  
  52. * ACC/AUX -> ACC, remainder in EXT
  53.  
  54. DIV    LDA #0
  55.     STA EXT+1
  56.     LDY #$10
  57. ]LOOP    ASL ACC
  58.     ROL ACC+1
  59.     ROL
  60.     ROL EXT+1
  61.     PHA
  62.     CMP AUX
  63.     LDA EXT+1
  64.     SBC AUX+1
  65.     BCC DIV2
  66.     STA EXT+1
  67.     PLA
  68.     SBC AUX
  69.     PHA
  70.     INC ACC
  71. DIV2    PLA
  72.     DEY
  73.     BNE ]LOOP
  74.     STA EXT
  75.     RTS
  76.  
  77. Note that I did not write these; I lifted them off the Merlin assembler disk.
  78. They work just like you would write one: you have two numbers, A and B.  
  79. Multiply A by each power of two contained in B.  They are the most efficient
  80. implementation of this that I have seen though (if you want to make it just
  81. a little faster, change PLA/PHA to TXA/TAX, or store ACC in X, etc.).
  82.  
  83.     evetS-
  84.